package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Department;
import cn.wolfcode.domain.Employee;
import cn.wolfcode.service.IDepartmentService;
import cn.wolfcode.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class LoginController {
    @Autowired
    private IEmployeeService employeeService;

    @RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session) {
        Employee employee = employeeService.login(username,password);
        if (employee == null) {
            model.addAttribute("msg","错误");
            return "forward:/login.jsp";
        }
        session.setAttribute("EMPLOYEE_IN_SESSION",employee);
        return "redirect:/department/list.do";

    }
}

